/* adcuxr.p - CUSTOMER RESPONSIBILITY-OWNING PROGRAM                          */
/* Copyright 1986-2004 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.18.4.1 $                                                          */
/*                                                                            */
/*V8:ConvertMode=NoConvert                                                    */
/*                                                                            */
/* REVISION: 9.1     LAST MODIFIED: 01/14/2000  BY: *N03S*  Hemanth Ebenezer  */
/* REVISION: 9.1     LAST MODIFIED: 01/14/2000  BY: *N06R*  Hemanth Ebenezer  */
/* REVISION: 9.1     LAST MODIFIED: 05/12/2000  BY: *N0B1*  David Morris      */
/* REVISION: 9.1     LAST MODIFIED: 06/26/2000  BY: *N059*  Hemanth Ebenezer  */
/* REVISION: 9.1     LAST MODIFIED: 10/17/2000  BY: *M0V4*  Kirti Desai       */
/* Revision: 1.13     BY: B. Gates           DATE: 12/04/00   ECO: *N0V1*     */
/* Revision: 1.13.2.4 BY: Murali Ayyagari    DATE: 01/25/01   ECO: *N0VS*     */
/* Revision: 1.17     BY: Russ Witt          DATE: 06/18/01   ECO: *P00J*     */

/* Revision: 1.18     BY: Vivek DSilva       DATE: 11/22/01   ECO: *M1QP*     */
/* $Revision: 1.18.4.1 $  BY: Gaurav Kerkar      DATE: 07/08/04   ECO: *P28X*     */
{mfdeclre.i}
/* Define Handles for the programs. */
{pxphdef.i glacxr}
{pxphdef.i gpacxr}
{pxphdef.i gpcodxr}
{pxphdef.i gplngxr}
{pxphdef.i gpsecxr}
{pxphdef.i icsixr}
{pxphdef.i mcexxr}
{pxphdef.i pxtools}
/* End Define Handles for the programs. */
{pxmaint.i}
define temp-table ttPhyCustomer like pm_mstr.
/* Constants used for processing price lists. */
{ppprlst.i}
/* ========================================================================== */
/* ******************************** FUNCTIONS ******************************* */
/* ========================================================================== */
/*============================================================================*/
FUNCTION isSelfBilling returns logical:
/*---------------------------------------------------------------------------
Purpose:  Checks to see if self billing is enabled
Exceptions:
Notes:
History:
---------------------------------------------------------------------------*/
define variable returnData as logical no-undo.
/* Flag to enable capture of self-billing information */
if can-find (first mfc_ctrl where
   mfc_field = "enable_self_bill"
   and mfc_seq = 2 and mfc_module = "ADG"
   and mfc_logical = yes) and
   can-find (_file where _file-name = "sbic_ctl") then do:
   return true.
end. /* can-find (_file where _file-name = "sbic_ctl") then do: */
else
   return false.
return (returnData).
END FUNCTION.
/* ========================================================================== */
/* ************************** INTERNAL PROCEDURES *************************** */
/* ========================================================================== */
/*============================================================================*/
PROCEDURE setModificationInfo:
/*---------------------------------------------------------------------------
   Purpose:     Stores audit entries into customer buffer
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define  parameter buffer pCustomerBuffer for pm_mstr .
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      /* STORE MODIFY DATE AND USERID */
      assign
         pm_mod_date = today
         pm_userid   = global_userid.
   end. /* do on error undo, return {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* setModificationInfo */
/*============================================================================*/
PROCEDURE createCustomer:
/*---------------------------------------------------------------------------
   Purpose:     Creates a record in the customer buffer.
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define  parameter buffer pCustomerBuffer for pm_mstr .
   define input parameter pCustomerNbr as character no-undo.
   define input parameter pCustomerName as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      create pCustomerBuffer.
      assign pm_addr = pCustomerNbr
             pm_sort = pCustomerName.
      {pxrun.i &PROC='setNewRecord' &PROGRAM='pxtools.p'
               &HANDLE=ph_pxtools
               &PARAM="(input buffer pCustomerBuffer:handle, yes)"}
   end. /* do on error undo, return {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* createCustomer */
/*============================================================================*/
PROCEDURE deleteCustomer:
/*---------------------------------------------------------------------------
   Purpose:     Deletes Customer record.
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define parameter buffer pCustomerBuffer for pm_mstr .
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      /* DELETE CUSTOMER MASTER */
      delete pCustomerBuffer.
   end. /* do on error undo, return {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* deleteCustomer */
/*============================================================================*/
PROCEDURE deleteEndUserAndMore:
/*---------------------------------------------------------------------------
   Purpose:     Deletes an enduser
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pCustomerKey as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      /* DELETE eud_det AND iss_mstr */
      {gprun.i ""adcsmtd.p"" "(input pCustomerKey)"}
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* deleteEndUserAndMore */
/*============================================================================*/
PROCEDURE deleteReservedLocationsForCustomer:
/*---------------------------------------------------------------------------
   Purpose:     Deletes Reserved Location records
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pCustomerAddress as character no-undo.
   define buffer loccdet for locc_det.
   define buffer ls_mstr for ls_mstr. /* required for processread of adarxr.p */
   /* IF ADDRESS ALSO EXISTS AS SHIP_TO THEN  RESERVED LOCATION RECORDS */
   /* WILL NOT BE DELETED AT THIS TIME BECAUSE WE DON'T KNOW IF         */
   /* THEY BELONG TO THE SHIP-TO OR CUSTOMER                            */
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      run processRead in getHandle(input "adarxr.p", false)
         (input pCustomerAddress,
          input "ship-to",
          buffer ls_mstr,
          input no,
          input no) .
      if return-value = {&RECORD-NOT-FOUND} then
      do :
         for each loccdet where loccdet.locc_addr = pCustomerAddress
         exclusive-lock:
            delete loccdet.
         end.
      end.
   end.
   return {&SUCCESS-RESULT}.
END PROCEDURE.  /* deleteReservedLocationsForCustomer */
/*============================================================================*/
PROCEDURE generateAnalysisCode:
/*---------------------------------------------------------------------------
   Purpose:     Generates analysis codes for new and modified records
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define parameter buffer bOldCustomer for ttPhyCustomer.
   define parameter buffer bCustomer for pm_mstr.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      if (new bcustomer)
            or
         (bCustomer.pm_addr <> bOldCustomer.pm_addr or
          bCustomer.pm_bill <> bOldCustomer.pm_bill or
          bCustomer.pm_class <> bOldCustomer.pm_class or
          bCustomer.pm_region <> bOldCustomer.pm_region or
          bCustomer.pm_site <> bOldCustomer.pm_site or
          bCustomer.pm_sort <> bOldCustomer.pm_sort or
          bCustomer.pm_type <> bOldCustomer.pm_type or
          bCustomer.pm_user1 <> bOldCustomer.pm_user1 or
          bCustomer.pm_user2 <> bOldCustomer.pm_user2) then do:
         {pxrun.i &PROC='generateCustAnalysisCode' &PROGRAM='gpacxr.p'
                  &HANDLE=ph_gpacxr
                  &PARAM="(bCustomer.pm_addr)"}
       end.
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* generateAnalysisCode */
/*============================================================================*/
PROCEDURE generateNextId:
/*---------------------------------------------------------------------------
   Purpose:     Generates a customer number for use
   Exceptions:  NONE
   Notes:This proc can only be used in API mode and never in character mode
   History:
---------------------------------------------------------------------------*/
   define output parameter pCustomerNbr as character no-undo.
   define variable myAppServer as handle no-undo.
   do on error undo, return error return-value:
     /* connect to the named appserver */
     {pxascon.i &APPSERVER='mfgpro' &MULTIDB=global_db &HANDLE=myAppServer}
     /* execute the adadgen.p in the new appserver*/
     {pxasrun.i &APPSERVER=myAppServer
                &PROGRAM='adadgen.p'
                &PARAM="(input global_user_lang_dir,
                         output pCustomerNbr)"
     }
     /* disconnect from the appserver*/
     {pxasdisc.i &HANDLE=myAppServer}
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* generateNextId */
/*============================================================================*/
PROCEDURE processRead:
/*---------------------------------------------------------------------------
   Purpose:     Reads Customer record depending on the lock & wait flags
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pAddressKey as character no-undo.
   define  parameter buffer pCustomerBuffer for pm_mstr .
   define input parameter pLockFlag as logical no-undo.
   define input parameter pWaitFlag as logical no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      if plockflag then do:
         if PWaitFlag then
            find pCustomerBuffer where pm_addr = pAddressKey
            exclusive-lock no-error.
         else do :
            find pCustomerBuffer where pm_addr = pAddressKey
            exclusive-lock no-wait no-error.
            if locked pCustomerBuffer then
               return {&RECORD-LOCKED} .
         end. /* ELSE DO */
      end. /* if plockflag then do: */
      else
         find pCustomerBuffer where pm_addr = pAddressKey no-lock no-error.
      if not avail pCustomerBuffer then
       return {&RECORD-NOT-FOUND}.
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* processRead */
/*============================================================================*/
PROCEDURE setGLDefaults:
/*---------------------------------------------------------------------------
   Purpose:     Sets GL defaults into customer record
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define  parameter buffer pCustomerBuffer for pm_mstr .
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      for first gl_ctrl
         fields (gl_ar_acct gl_ar_sub gl_ar_cc gl_base_curr) no-lock :
      end.
      assign
         pm_ar_acct = gl_ar_acct
         pm_ar_sub  = gl_ar_sub
         pm_ar_cc   = gl_ar_cc
         pm_curr    = gl_base_curr.
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* setGLDefaults */
/*============================================================================*/
PROCEDURE validateEndUserData:
/*---------------------------------------------------------------------------
   Purpose:     Validates if an End User record is used/active
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pEndUserCustomer as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      find first eu_mstr where eu_addr = pEndUserCustomer
         no-lock no-error.
      if available eu_mstr then do:
         /* MESSAGE #1368 - CANNOT DELETE. ADDRESS USED AS AN END USER */
         {pxmsg.i
            &MSGNUM=1368
            &ERRORLEVEL={&APP-ERROR-RESULT}}
         return error {&APP-ERROR-RESULT}.
      end. /* if available eu_mstr then do: */
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* validateEndUserData */
/*============================================================================*/
PROCEDURE validateInvoiceHistory:
/*---------------------------------------------------------------------------
   Purpose:     Validates if Invoices are present for a Customer
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pInvHistCustomer as character no-undo.
   define output parameter pInvoiceHistoryConfirm as logical no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      if can-find(first ih_hist where ih_cust = pInvHistCustomer) then do :
         /* MESSAGE #1369 -
         INVOICE HISTORY EXISTS FOR THIS CUSTOMER. CONTINUE? */
         {pxmsg.i
            &MSGNUM=1369
            &ERRORLEVEL={&WARNING-RESULT}
            &CONFIRM=pInvoiceHistoryConfirm }
         return error {&APP-ERROR-RESULT}.
      end. /* if available ih_hist then do: */
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* validateInvoiceHistory */
/*============================================================================*/
PROCEDURE validateOpenAR:
/*---------------------------------------------------------------------------
   Purpose:     Validates for open Accounts Receivables of a customer
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pARCustomer as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      if can-find(first ar_mstr where ar_cust = pARCustomer)
         or can-find(first ar_mstr where ar_bill = pARCustomer) then do:
         /* MESSAGE #356 -
         DELETE NOT ALLOWED, ACCOUNTS RECEIVABLE RECORDS EXIST */
         {pxmsg.i
            &MSGNUM=356
            &ERRORLEVEL={&APP-ERROR-RESULT}}
         return error {&APP-ERROR-RESULT}.
      end. /* or can-find(first ar_mstr where ar_bill = pARCustomer) then do: */
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* validateOpenAR */
/*============================================================================*/
PROCEDURE validateOpenQuotes:
/*---------------------------------------------------------------------------
   Purpose:     Validates for open Quotations of a customer
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pQuotationCustomer as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      /* CHECK FOR OPEN QUOTES */
      if can-find(first qo_mstr
                     where qo_cust = pQuotationCustomer)
      or can-find(first qo_mstr
                     where qo_bill = pQuotationCustomer)
      then do:
         for first qo_mstr
            fields (qo_bill qo_cust qo_nbr)
            where qo_cust = pQuotationCustomer
         no-lock:
         end. /* FOR FIRST qo_mstr */
         if not available qo_mstr
         then
            for first qo_mstr
               fields (qo_bill qo_cust qo_nbr)
               where qo_bill = pQuotationCustomer
            no-lock:
            end. /* FOR FIRST qo_mstr */
         if available qo_mstr
         then do:
            /* MESSAGE #121 - DELETE NOT ALLOWED, EXISTING QUOTE */
            {pxmsg.i
                &MSGNUM=121
                &ERRORLEVEL={&APP-ERROR-RESULT}
                &MSGARG1=qo_nbr}
             return error {&APP-ERROR-RESULT}.
         end. /* IF AVAILABLE qo_mstr */
      end. /* qo_bill = pQuotationCustomer) then do: */
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* validateOpenQuotes */
/*============================================================================*/
PROCEDURE validateOpenSO:
/*---------------------------------------------------------------------------
   Purpose:     Validates for open Sales Orders of a customer
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pSOCustomer as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      /* CHECK FOR OPEN SALES ORDERS */
      if can-find(first so_mstr
                     where so_cust = pSOCustomer)
      or can-find(first so_mstr
                     where so_bill = pSOCustomer)
      or can-find(first so_mstr
                     where so_ship = pSOCustomer)
      then do:
         for first so_mstr
            fields (so_bill so_cust so_ship so_nbr)
            where so_cust = pSOCustomer
         no-lock:
         end. /* FOR FIRST so_mstr */
         if not available so_mstr
         then
            for first so_mstr
               fields (so_bill so_cust so_ship so_nbr)
               where so_bill = pSOCustomer
            no-lock:
            end. /* FOR FIRST so_mstr */
         if not available so_mstr
         then
            for first so_mstr
               fields (so_bill so_cust so_ship so_nbr)
               where so_ship = pSOCustomer
            no-lock:
            end. /* FOR FIRST so_mstr */

         if available so_mstr
         then do:

            /* MESSAGE #607 - DELETE NOT ALLOWED, EXISTING SALES ORDER */
            {pxmsg.i
                &MSGNUM=607
                &ERRORLEVEL={&APP-ERROR-RESULT}
                &MSGARG1=so_nbr}
            return error {&APP-ERROR-RESULT}.
         end. /*IF AVAILABLE so_mstr */

      end. /* IF CAN FIND (FIRST so_mstr ... */

   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.

END PROCEDURE. /* validateOpenSO */
/*============================================================================*/
PROCEDURE validateSRO:
/*---------------------------------------------------------------------------
   Purpose:     Validates for open Service Repair Orders of a customer
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pSROCustomer as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      /*CHECK FOR SRO'S */
      if can-find(first sro_mstr where sro_cust = pSROCustomer
         and sro_closed = no) then do:
         find first sro_mstr where sro_cust = pSROCustomer
            and sro_closed = no no-lock.
         /* MESSAGE #309 - DELETE NOT ALLOWED, S/RO EXISTS */
         {pxmsg.i
            &MSGNUM=309
            &ERRORLEVEL={&APP-ERROR-RESULT}
            &MSGARG1=sro_nbr}
         return error {&APP-ERROR-RESULT}.
      end. /* and sro_closed = no) then do: */
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* validateSRO */
/*============================================================================*/
PROCEDURE validateSvcContracts:
/*---------------------------------------------------------------------------
   Purpose:     Validates for open Service Contracts of a customer
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pSACustomer as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      /* CHECK FOR CUSTOMER SERVICE CONTRACTS */
      find first sa_mstr where sa_cust = pSACustomer
         no-lock no-error.
      if available sa_mstr then do:
         /* MESSAGE #7232 -
         DELETE NOT ALLOWED. SERVICE CONTRACT(S)/QUOTE(S) EXIST */
         {pxmsg.i
            &MSGNUM=7232
            &ERRORLEVEL={&APP-ERROR-NO-REENTER-RESULT}}
         return error {&APP-ERROR-NO-REENTER-RESULT}.
      end. /* if available sa_mstr then do: */
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* validateSvcContracts */
/*============================================================================*/
PROCEDURE validateSvcData:
/*---------------------------------------------------------------------------
   Purpose:     Validates for Service Data of a customer
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pSvcEndUserCustomer as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      /* BEFORE AN END USER CAN BE DELETED, ADEUMT.P CHECKS FOR THE */
      /* EXISTENCE OF ANY TYPE OF SERVICE DATA, SO HERE, WE ONLY    */
      /* NEED TO CHECK FOR END USERS.                               */
      find first eu_mstr where eu_cm_nbr = pSvcEndUserCustomer no-lock no-error.
     if available eu_mstr then do :
         /* MESSAGE #7438 -
         CANNOT DELETE. ENGINEER WORKS WITH CUSTOMER # END USER # */
         {pxmsg.i
            &MSGNUM=7438
            &ERRORLEVEL={&APP-ERROR-RESULT}
            &MSGARG1=eu_cm_nbr
            &MSGARG2=eu_addr}
         return error {&APP-ERROR-RESULT}.
      end. /* if available eu_mstr */
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* validateSvcData */
/*============================================================================*/
PROCEDURE setSortName:
/*---------------------------------------------------------------------------
   Purpose:     Sets sort name in customer buffer
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define parameter buffer pCustBuffer for pm_mstr.
   define input parameter pCustomerSortName as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      if pm_sort = "" then pm_sort = pCustomerSortName.
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* setSortName */
/*============================================================================*/
PROCEDURE validateAccountCurrency:
/*---------------------------------------------------------------------------
   Purpose:     Validate Account Currency
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pAccountCode as character no-undo.
   define input parameter pCustomerCurr as character no-undo.
   define input parameter pBaseCurr as character no-undo.
   define variable lAccountCurrency like ac_curr no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      {pxrun.i &PROC='getAccountCurrency' &PROGRAM='glacxr.p'
               &HANDLE=ph_glacxr
               &PARAM="(input pAccountCode,
                        output lAccountCurrency)"
               &NOAPPERROR=true
               &CATCHERROR=true
      }
      if return-value = {&SUCCESS-RESULT}
         and lAccountCurrency <> pCustomerCurr
         and lAccountCurrency <> pBaseCurr
      then do:
         /* MESSAGE # 1220 -
                ACCOUNT CURRENCY <> EITHER CUSTOMER OR BASE CURRENCY */
         /* Not returning an error here because this is just a warning. */
          {pxmsg.i &MSGNUM=1220 &ERRORLEVEL={&APP-ERROR-RESULT}}
           return error {&APP-ERROR-RESULT}.
          /* RETURNING AN ERROR HERE */
      end. /* IF RETURN-VALUE = {&SUCCESS-RESULT  */
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* validateAccountCurrency */
/*============================================================================*/
PROCEDURE validateCurrency:
/*---------------------------------------------------------------------------
   Purpose:     Validates if Currency is in Union
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pCurrency as character no-undo.
   define output parameter pIsUnion as logical no-undo.
   define output parameter pIsMember as logical no-undo.
   define variable unionCurr as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      /* CHECK IF CUSTOMER CURRENCY IS UNION CURRENCY */
      {pxrun.i &PROC='validateCurrencyInUnion' &PROGRAM='mcexxr.p'
               &HANDLE=ph_mcexxr
               &PARAM="(input pCurrency,
                        output unionCurr,
                        output pIsUnion,
                        output pIsMember)"}
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* validateCurrency */
/*============================================================================*/
PROCEDURE validateCurrencyCode:
/*---------------------------------------------------------------------------
   Purpose:     Validates Currency Code
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pOldCurr as character no-undo.
   define input parameter pNewCurr as character no-undo.
   do on error undo, return error return-value:
      if pOldCurr <> pNewCurr then do:
         {pxrun.i &PROC='validateCurrency' &PROGRAM='mcexxr.p'
                  &HANDLE=ph_mcexxr
                  &PARAM="(input pNewCurr)"}
      end.  /* IF pOldCurr <> pNewCurr */
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* validateCurrencyCode */
/*============================================================================*/
PROCEDURE validateDualCurrencies:
/*---------------------------------------------------------------------------
   Purpose:     Validates the dual Currency Code of customer
   Exceptions:  NONE
   Notes:
   History:
---------------------------------------------------------------------------*/
   define input parameter pCmCurr as character no-undo.
   define input parameter pCmScurr as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      if pCmScurr = pCmCurr then do:
         /* MESSAGE #2670 -  BOTH CURRENCIES CANNOT BE THE SAME CURRENCY */
         {pxmsg.i &MSGNUM=2670 &ERRORLEVEL={&APP-ERROR-RESULT}}
         return error {&APP-ERROR-RESULT}.
      end. /* if pCmScurr = pCmCurr then do: */
   end. /* do on error undo, return error {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* validateDualCurrencies */
/*============================================================================*/
PROCEDURE setDefaultEMTType :
/*---------------------------------------------------------------------------
  Purpose:     Set the Default EMT type of customer
  Exceptions:  NONE
  Notes:
  History:
---------------------------------------------------------------------------*/
   define  parameter buffer pCustomerBuffer for pm_mstr.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      if pm_btb_type = "" then pm_btb_type = "01".
   end.
   return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE updateCreditDate :
/*---------------------------------------------------------------------------
  Purpose:     Updates the credit Date of customer
  Exceptions:  NONE
  Notes:
  History:
---------------------------------------------------------------------------*/
   define  parameter buffer pCustomerBuffer for pm_mstr.
   define input parameter pOldCreditLimit as decimal no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
         if pm_cr_limit <> pOldCreditLimit and pm_cr_update < today then
            pm_cr_update = today.
         if pm_cr_update = ? then pm_cr_update = today.
   end.
   return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateUM :
/*---------------------------------------------------------------------------
  Purpose:     Validates Unit of Measure
  Exceptions:  NONE
  Notes:
  History:
---------------------------------------------------------------------------*/
   define input parameter pOldUM as character no-undo.
   define input parameter pFrUM as character no-undo.
   define input parameter pOldFrList as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
            if pOldUM <> pFrUM and pOldFrList <> "" then do:
               /* MESSAGE #675 - UNIT OF MEASURE HAS CHANGED */
               {pxmsg.i
                  &MSGNUM=675
                  &ERRORLEVEL={&WARNING-RESULT}}
            end. /* if pOldUM <> pFrUM and pOldFrList <> "" then do: */
   end.
   return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE getDualCurrencyPolicy:
/*------------------------------------------------------------------------------
  Purpose:     Get the dual currency print flag from the et_ctrl file.
  Exceptions:  {&APP-ERROR-RESULT}
  Notes:       This probably belongs in an EMU ROP!
------------------------------------------------------------------------------*/
   define output parameter pDualCurrencyFlag as logical no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      for first et_ctrl no-lock: end.
      if not available et_ctrl then do:
         create et_ctrl.
      end.
      pDualCurrencyFlag = et_ctrl.et_print_dc.
   end.
   return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateType :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_type
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateGeneralizedCodes' &PROGRAM='gpcodxr.p'
              &HANDLE=ph_gpcodxr
              &PARAM = "(input 'pm_type',
                         input '',
                         input pValue,
                         input '')"
              &FIELD-LIST=pm_type
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateCreditTerms :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_cr_terms
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
     /* 840 - CREDIT TERMS CODE MUST EXIST OR BE BLANK */
     if not(can-find(ct_mstr where ct_code = pValue) or pValue = "") then do:
        {pxmsg.i &MSGNUM=840 &ERRORLEVEL={&APP-ERROR-RESULT}
                 &FIELDNAME='pm_cr_terms'}
        return error {&APP-ERROR-RESULT}.
     end.
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateDiscPct :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_disc_pct
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as decimal no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_disc_pct',
                         input '')"
              &FIELD-LIST=pm_disc_pct
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateLanguage :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_lang
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateLanguageCode' &PROGRAM='gplngxr.p'
              &HANDLE=ph_gplngxr
              &PARAM = "(input 'pm_mstr.pm_lang',
                         input pValue,
                         input yes,
                         input '')"
              &FIELD-LIST=pm_lang
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateSite :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_site
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateSite' &PROGRAM='icsixr.p'
              &HANDLE=ph_icsixr
              &PARAM = "(input 'pm_mstr.pm_site',
                         input pValue,
                         input no,
                         input '')"
              &FIELD-LIST=pm_site
     }
     if return-value = {&SUCCESS-RESULT} then do :
      {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
                &HANDLE=ph_gpsecxr
                &PARAM = "(input 'pm_site',
                           input '')"
                &FIELD-LIST=pm_site
      }
     end. /* IF RETURN-VALUE = {SUCCESS-RESULT} */
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateClass :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_class
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateGeneralizedCodes' &PROGRAM='gpcodxr.p'
              &HANDLE=ph_gpcodxr
              &PARAM = "(input 'pm_class',
                         input '',
                         input pValue,
                         input '')"
              &FIELD-LIST=pm_class
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateCreditRating :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_cr_rating
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
  do on error undo, return error return-value:
   {pxrun.i &PROC = 'validateGeneralizedCodes' &PROGRAM='gpcodxr.p'
            &HANDLE=ph_gpcodxr
            &PARAM = "(input 'pm_cr_rating',
                       input '',
                       input pValue,
                       input '')"
            &FIELD-LIST=pm_cr_rating
   }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateRegion :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_cr_rating
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error return-value:
   {pxrun.i &PROC = 'validateGeneralizedCodes' &PROGRAM='gpcodxr.p'
            &HANDLE=ph_gpcodxr
            &PARAM = "(input 'pm_region',
                       input '',
                       input pValue,
                       input '')"
            &FIELD-LIST=pm_region
   }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateShipVia :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_shipvia
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateGeneralizedCodes' &PROGRAM='gpcodxr.p'
              &HANDLE=ph_gpcodxr
              &PARAM = "(input 'pm_shipvia',
                         input '',
                         input pValue,
                         input '')"
              &FIELD-LIST=pm_shipvia
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateArAccount :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_ar_acct
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_ar_acct',
                         input '')"
              &FIELD-LIST=pm_ar_acct
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateArCostCenter :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_ar_cc
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_ar_cc',
                         input '')"
              &FIELD-LIST=pm_ar_cc
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateArSubAccount :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_ar_sub
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_ar_sub',
                         input '')"
              &FIELD-LIST=pm_ar_sub
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateCreditHold :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_cr_hold
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as logical no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_cr_hold',
                         input '')"
              &FIELD-LIST=pm_cr_hold
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateCreditLimit :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_cr_limit
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as decimal no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_cr_limit',
                         input '')"
              &FIELD-LIST=pm_cr_limit
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateCurrencyForAccess :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_curr
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_curr',
                         input '')"
              &FIELD-LIST=pm_curr
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateDunLetter :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_dun
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as logical no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_dun',
                         input '')"
              &FIELD-LIST=pm_dun
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateFinanceCharge :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_fin
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as logical no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_fin',
                         input '')"
              &FIELD-LIST=pm_fin
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateFixedPrice :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_fix_pr
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as logical no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_fix_pr',
                         input '')"
              &FIELD-LIST=pm_fix_pr
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validatePriceList :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_pr_list2
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_pr_list2',
                         input '')"
              &FIELD-LIST=pm_pr_list2
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateSecondCurrency :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_scurr
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_scurr',
                         input '')"
              &FIELD-LIST=pm_scurr
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateAccountStatements :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_stmt
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as logical no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_stmt',
                         input '')"
              &FIELD-LIST=pm_stmt
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateStatementCyclePrint :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_stmt_cyc
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_stmt_cyc',
                         input '')"
              &FIELD-LIST=pm_stmt_cyc
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateTaxable :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_taxable
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as logical no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_taxable',
                         input '')"
              &FIELD-LIST=pm_taxable
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateTaxIncluded :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_tax_in
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as logical no-undo.
   do on error undo, return error return-value:
     {pxrun.i &PROC = 'validateFieldAccess' &PROGRAM='gpsecxr.p'
              &HANDLE=ph_gpsecxr
              &PARAM = "(input 'pm_tax_in',
                         input '')"
              &FIELD-LIST=pm_tax_in
     }
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateBillToAddress :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_bill
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
     /* 7255 - CUSTOMER CODE MUST EXIST OR BE BLANK */
     if not(can-find(pm_mstr where pm_addr = pValue) or pValue = "") then do:
        {pxmsg.i &MSGNUM=7255 &ERRORLEVEL={&APP-ERROR-RESULT}
             &FIELDNAME = 'pm_mstr.pm_bill'}
        return error {&APP-ERROR-RESULT}.
     end.
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateServiceTerms :
/*------------------------------------------------------------------------------
  Purpose:     Validate pm_mstr.pm_serv_terms
  Exceptions:  NONE
  Notes:
  History:
------------------------------------------------------------------------------*/
   define input parameter pValue as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
     /* 7254 - SERVICE TERMS CODE MUST EXIST OR BE BLANK */
     if not(can-find(ct_mstr where ct_code = pValue) or pValue = "") then do:
        {pxmsg.i &MSGNUM=7254 &ERRORLEVEL={&APP-ERROR-RESULT}}
        return error {&APP-ERROR-RESULT}.
     end.
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
/*============================================================================*/
PROCEDURE validateOpenPRJ:
/*--------------------------------------------------------------------
  Purpose:     Validates if there are open PRM Projects for a customer.
  Exceptions:  NONE
  Notes:
  History:     Created 05/12/2000 By: *N0B1*
--------------------------------------------------------------------*/
   define input parameter pPRJCustomer as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      /* CHECK FOR OPEN PRM PROJECTS */
      for first prj_mstr
         fields(prj_nbr) no-lock
         where prj_cust    = pPRJCustomer
         or    prj_bill_to = pPRJCustomer:
      end.
      if available prj_mstr then do:
         /* MESSAGE #3895 - DELETE NOT ALLOWED, REFERENCED ON PROJECT */
         {pxmsg.i
            &MSGNUM=3895
            &ERRORLEVEL={&APP-ERROR-RESULT}
            &MSGARG1=prj_nbr}
         return error {&APP-ERROR-RESULT}.
      end. /* IF AVAILABLE PRJ_MSTR */
   end. /* DO ON ERROR UNDO, RETURN ERROR {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* validateOpenPRJ */
/*============================================================================*/
PROCEDURE validateInvSchedules:
/*--------------------------------------------------------------------
  Purpose:     Validates if there are PRM Invoice Schedules for a customer.
  Exceptions:  NONE
  Notes:
  History:     Created 05/12/2000 By: *N0B1*
/* REVISION: 9.1    LAST MODIFIED: 08/17/00 BY: *N0LJ* Mark Brown             */
--------------------------------------------------------------------*/
   define input parameter pPRJCustomer as character no-undo.
   do on error undo, return error {&GENERAL-APP-EXCEPT}:
      /* CHECK FOR OPEN PRM PROJECTS */
      for first ins_mstr
         fields(ins_sched_nbr ins_prj_nbr) no-lock
         where ins_bill_to = pPRJCustomer:
      end.
      if available ins_mstr then do:
         /* MESSAGE #3896 - */
         /* DELETE NOT ALLOWED, REFERENCED ON INVOICE SCHEDULE # OF PROJECT */
         {pxmsg.i
            &MSGNUM=3896
            &ERRORLEVEL={&APP-ERROR-RESULT}
            &MSGARG1=ins_sched_nbr
            &MSGARG2=ins_prj_nbr}
         return error {&APP-ERROR-RESULT}.
      end. /* IF AVAILABLE INS_MSTR */
   end. /* DO ON ERROR UNDO, RETURN ERROR {&GENERAL-APP-EXCEPT}: */
   return {&SUCCESS-RESULT}.
END PROCEDURE. /* validateOpenPRJ */
/*============================================================================*/
PROCEDURE validateWrite :
/*------------------------------------------------------------------------------
  Purpose:     Validate Customer Buffer
  Exceptions:  Whatever is returned from the individual run statements.
  Notes:       This procedure is called by the Customer data type controller to
               perform the schema validations for the pm_mstr fields displayed
               in the Customer Maintenance application.
  History:
------------------------------------------------------------------------------*/
   define parameter buffer pCustomerBuffer for pm_mstr.
   do on error undo, return error return-value:
      {pxrun.i &PROC='validateType'
               &PARAM="(input pm_type)"}
      {pxrun.i &PROC='validateCreditTerms'
               &PARAM="(input pm_cr_terms)"}
      {pxrun.i &PROC='validateDiscPct'
               &PARAM="(input pm_disc_pct)"}
      {pxrun.i &PROC='validateLanguage'
               &PARAM="(input pm_lang)"}
      {pxrun.i &PROC='validateClass'
               &PARAM="(input pm_class)"}
      {pxrun.i &PROC='validateCreditRating'
               &PARAM="(input pm_cr_rating)"}
      {pxrun.i &PROC='validateRegion'
               &PARAM="(input pm_region)"}
      {pxrun.i &PROC='validateSite'
               &PARAM="(input pm_site)"}
      {pxrun.i &PROC='validateShipVia'
               &PARAM="(input pm_shipvia)"}
      {pxrun.i &PROC='validateArAccount'
               &PARAM="(input pm_ar_acct)"}
      {pxrun.i &PROC='validateArCostCenter'
               &PARAM="(input pm_ar_cc)"}
      {pxrun.i &PROC='validateArSubAccount'
               &PARAM="(input pm_ar_sub)"}
      {pxrun.i &PROC='validateCreditHold'
               &PARAM="(input pm_cr_hold)"}
      {pxrun.i &PROC='validateCreditLimit'
               &PARAM="(input pm_cr_limit)"}
      {pxrun.i &PROC='validateCurrencyForAccess'
               &PARAM="(input pm_curr)"}
      {pxrun.i &PROC='validateDunLetter'
               &PARAM="(input pm_dun)"}
      {pxrun.i &PROC='validateFinanceCharge'
               &PARAM="(input pm_fin)"}
      {pxrun.i &PROC='validateFixedPrice'
               &PARAM="(input pm_fix_pr)"}
      {pxrun.i &PROC='validatePriceList'
               &PARAM="(input pm_pr_list2)"}
      {pxrun.i &PROC='validateSecondCurrency'
               &PARAM="(input pm_scurr)"}
      {pxrun.i &PROC='validateAccountStatements'
               &PARAM="(input pm_stmt)"}
      {pxrun.i &PROC='validateStatementCyclePrint'
               &PARAM="(input pm_stmt_cyc)"}
      {pxrun.i &PROC='validateBillToAddress'
               &PARAM="(input pm_bill)"}
  end.
  return {&SUCCESS-RESULT}.
END PROCEDURE.
      